package blue_bridge_cup_learning.data_struct_code;

public class Stack_Link {
    private Node top;

    public class Node {
        int value;
        Node next;

        public Node(int value) {
            this.value = value;
            this.next = null;
        }
    }

    public Stack_Link() {
        this.top = null;
    }

    public boolean isEmpty() {
        return this.top == null;
    }

    public void Push(int value) {
        Node newNode = new Node(value);
        newNode.next = this.top;
        this.top = newNode;
    }

    public int Pop() {
        if (this.isEmpty()) {
            System.out.println("栈为空，无法出栈");
            return -1;
        }
        int value = this.top.value;
        this.top = this.top.next;
        return value;
    }

    public void PrintStack() {
        Node current = this.top;
        while (current != null) {
            System.out.println(current.value);
            current = current.next;
        }
    }

    public static void main(String[] args) {
        Stack_Link stack_link = new Stack_Link();
        stack_link.Push(1);
        stack_link.Push(2);
        stack_link.Push(3);
        stack_link.PrintStack();
    }
}
